﻿using MediatR;
using T.Vehicleservice.API.Application.Command.ViolationRecordCommand;
using T.Vehicleservice.Repository.Interface;

namespace T.Vehicleservice.API.Application.CommandHandlers.ViolationRecordHandler
{
    /// <summary>
    /// 批删（违章记录）
    /// </summary>
    public class ViolationRecordDeleteAllCommandHander : IRequestHandler<ViolationRecordDeleteAllCommand, int>
    {
        private readonly IViolationRecordRepository _violationRecordRepository;
        public ViolationRecordDeleteAllCommandHander(IViolationRecordRepository violationRecordRepository)
        {
            _violationRecordRepository = violationRecordRepository;
        }
        public async Task<int> Handle(ViolationRecordDeleteAllCommand request, CancellationToken cancellationToken)
        {
            var DelVio = request.VioIds;
            foreach (var item in DelVio)
            {
                var DelVioList = _violationRecordRepository.GetModelAsync(item).Result;
                DelVioList.IsDeleted = true;
               
                await _violationRecordRepository.UpdateAsync(DelVioList);
            }
            return 1;
        }
    }
}
